#include <msp430f5309.h>
#include <intrinsics.h>

#define st(x)      do { x } while (__LINE__ == -1)

#define __bsp_ENABLE_INTERRUPTS__()         __enable_interrupt()
#define __bsp_DISABLE_INTERRUPTS__()        __disable_interrupt()
#define __bsp_INTERRUPTS_ARE_ENABLED__()    (__get_SR_register() & GIE)

#define __bsp_ISTATE_T__                    istate_t
#define __bsp_GET_ISTATE__()                __get_interrupt_state()
#define __bsp_RESTORE_ISTATE__(x)           __set_interrupt_state(x)

#define __bsp_QUOTED_PRAGMA__(x)    _Pragma(#x)
#define __bsp_ISR_FUNCTION__(f,v)   __bsp_QUOTED_PRAGMA__(vector=v) __interrupt void f(void); \
                                    __bsp_QUOTED_PRAGMA__(vector=v) __interrupt void f(void)

#define bspIState_t __bsp_ISTATE_T__

#define BSP_ENTER_CRITICAL_SECTION(x)   st( x = __bsp_GET_ISTATE__(); __bsp_DISABLE_INTERRUPTS__(); )
#define BSP_EXIT_CRITICAL_SECTION(x)    __bsp_RESTORE_ISTATE__(x)
#define BSP_CRITICAL_STATEMENT(x)       st( bspIState_t s;                    \
                                            BSP_ENTER_CRITICAL_SECTION(s);    \
                                            x;                                \
                                            BSP_EXIT_CRITICAL_SECTION(s); )

////////////////////////////////////////////////////////////////////////////
// Pin Definitions
////////////////////////////////////////////////////////////////////////////

extern unsigned char rxBuffer[64];

// Port 1 pin definitions.
// Data bus to column drivers (and D0 to row drivers).

// Port LCD pin definitions.
#define LATCH         (1 << 1)
#define PHASE_SHORT   (1 << 2)
#define PHASE_LONG    (1 << 3)
#define nEN_VDD       (1 << 1)
#define PL_EN         (1 << 0)
#define RCLK          (1 << 3)

#define nEN_3V        (1 << 0)
#define CCLK          (1 << 1)
#define EN_TEMP       (1 << 4)
#define EN_HV         (1 << 2)
#define ENABLE        (1 << 3)
#define TEMP          (1 << 0)

// Display configuration.
// (Y160 = FRAME, Y159 = COM0, ..., Y88 = COM71, Y87 = FRAME)
#define FIRST_ROW 1
#define NUM_ROWS  128

// User-defined functions
extern void set_DATA(unsigned char data); 
extern void set_LATCH(void); 
extern void clr_LATCH(void); 
extern void set_PHASE_SHORT(void); 
extern void clr_PHASE_SHORT(void); 
extern unsigned char get_S1(void); 
extern void set_LED(void); 
extern void clr_LED(void);    
extern void tog_LED(void);   
extern void set_PHASE_LONG(void);
extern void clr_PHASE_LONG(void);
extern void set_nEN_VDD(void);  
extern void clr_nEN_VDD(void);
extern void set_PL_EN(void); 
extern void clr_PL_EN(void); 
extern void set_RCLK(void); 
extern void clr_RCLK(void);     
extern void set_PHASE(void); 
extern void clr_PHASE(void);  

extern void set_nEN_3V(void); 
extern void clr_nEN_3V(void);  
extern void set_CCLK(void);
extern void clr_CCLK(void);     
extern void set_EN_TEMP(void);   
extern void clr_EN_TEMP(void);   
extern void set_EN_HV(void);  
extern void clr_EN_HV(void);   
extern void set_ENABLE(void); 
extern void clr_ENABLE(void); 

extern void tgl_PHASE(void);          
extern void tgl_LATCH_RCLK_PHASE(void); 
extern void clr_LATCH_RCLK(void);    

#define MAX_CMD_SIZE      35

